import { HTTP } from "@/tools";
import { ApplicationUseType, StandardQuery, StandardPagingResult, PagingQuery, StandardResponse } from "./standard";

interface SysEmpParam {
    id: number,
    jobNum: string,
    orgId: number,
    orgName: string,
    posIdList: number[],
}
export interface SystemUserSlectQueryParms extends StandardQuery {
    account: string,
    avatar: number,
    birthday: string,
    email: string,
    grantOrgIdList: number[],
    grantRoleIdList: number[],
    id: number,
    name: string,
    newPassword: string,
    nickName: string,
    password: string,
    phone: string,
    roleId: number,
    sex: number,
    status: number,
    sysEmpParam: SysEmpParam,
    tel: string,
    tenantId: string,
    sysType: ApplicationUseType
}
export interface ExtendsInfo {
    // 机构id
    orgId: number,
    // 职位id
    posId: number,
}

/**
 * 用户机构信息
 * @prop {ExtendsInfo} extIds 拓展信息列表
 * @prop {Number} id 数据库id
 * @prop {String} jobNum 工号
 * @prop {Number} orgId 所属主要机构
 * @prop {String} orgName 所属机构名称
 * @prop {Array<Number>} posIdList 所属主要职位,多选
 */
interface UserEmpInfo {
    // 附属信息列表,机构,职位,职位单选
    extIds: ExtendsInfo[],
    // 附属信息列表,机构,职位,职位单选,这个字段是列表返回的,或者使用详情返回而存在的,并非表单提交时存在
    extOrgPos?: null | ExtendsInfo[],
    id?: number,
    jobNum: string,
    orgId: number,
    orgName: string,
    // 职位列表
    posIdList: number[],
    //  职位列表,这个字段是列表返回的,或者使用详情返回而存在的,并非表单提交时存在
    positions?: { postCode: string, posId: string, posName: string }[],
    tenantId: string
}
export interface UserListRaw {
    account: string,
    avatar: number,
    birthday: string,
    email: string,
    id: number,
    name: string,
    nickName: string,
    phone: string,
    sex: number,
    status: number,
    // sysEmpInfo: UserEmpInfo,
    sysEmpParam?: UserEmpInfo,
    tel: string,
    tenantId: number
}
export interface SystemUserItem {
    id: number,
    name: string
}
export async function getSystemUserSelect(params?: Partial<SystemUserSlectQueryParms>) {
    return HTTP.post<any, SystemUserItem[]>('/sysUser/selector', params)
}

export interface OnlineUserListInfo {
    account: string,
    lastLoginAddress: string,
    lastLoginBrowser: string,
    lastLoginIp: string,
    lastLoginOs: string,
    lastLoginTime: string,
    nickName: string,
    sessionId: string
}
/**
 * 给出当前在线用户列表
 * @param params 
 * @returns 
 */
export async function GetOnlineUserList(params: PagingQuery) {
    return HTTP.post<any, StandardPagingResult<OnlineUserListInfo>>('/sysOnlineUser/list', params)
}
/**
 * 强制下线用户
 * @param params 
 */
export async function OnlineUserForceExixt(params: Partial<{ account: string, sessionId: string }>) {
    return HTTP.post('/sysOnlineUser/forceExist', params)
}

export async function GetUserListByPaging(params: Partial<StandardQuery>) {
    return HTTP.post<StandardResponse<StandardPagingResult<UserListRaw>>>('/sysUser/page', params)
}